package com.isunland.managesystem.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.isunland.managesystem.R;
import com.isunland.managesystem.adapter.FormDetailAdapter;
import com.isunland.managesystem.base.BaseConfirmDialogFragment;
import com.isunland.managesystem.base.BaseFragment;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.VolleyResponse;
import com.isunland.managesystem.entity.BaseParams;
import com.isunland.managesystem.entity.CertificateNoContent;
import com.isunland.managesystem.entity.CompleteMessage;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.DataStatus;
import com.isunland.managesystem.entity.FormDetail;
import com.isunland.managesystem.entity.FormDetailOriginal;
import com.isunland.managesystem.entity.HintNumber;
import com.isunland.managesystem.entity.RSealsUseApp;
import com.isunland.managesystem.entity.SealUseDetailParams;
import com.isunland.managesystem.entity.SuccessMessage;
import com.isunland.managesystem.entity.SystemConstant;
import com.isunland.managesystem.entity.Task;
import com.isunland.managesystem.utils.DialogUtil;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.utils.MyUtils;
import com.isunland.managesystem.utils.SharedPreferencesUtil;
import com.isunland.managesystem.utils.ToastUtil;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: huxiaodan
 * 创建时间: 2016/12/6 18:13
 */

public class ToDoFormDetailFragment extends BaseFragment {

  public static final int TYPE_AGREE = 1;// 1.0
  public static final int TYPE_REFUSE = 2;// volleyComplete(TYPE_REFUSE);
  public static final int TYPE_REFUSE_TO_ORGANIZER = 3;// volleyComplete(TYPE_REFUSE_TO_ORGANIZER);
  public static final int TYPE_AGAINST = 4;// volleyComplete(TYPE_AGAINST );
  public static final int TYPE_ABORT = 5;// volleyComplete("0", "");
  private static final String EXTRA_TASK =
      "com.isunland.managesystem.ui.ToDoFormDetailFragment.EXTRA_TASK";
  private static final int REQUEST_CONVERT = 1;//转办
  private static final int REQUEST_FORMDETAIL = 2;//表单详情
  private static final int TYPE_STOP = 6;
  private int mOperation;
  private ListView mListView;
  private EditText mEtAdvise;
  private Button mBtnChild;

  private BaseVolleyActivity mActivity;
  private CurrentUser mUser;
  private Task mTask;
  private String mTaskId;
  private FormDetailAdapter mAdapter;
  private FormDetailOriginal mFormDetailOriginal;

  private String mUserNodeType;// 所在流程环节,用于显示不同的界面效果和不同的菜单.
  private RadioButton mRbTwo;
  private RadioButton mRbThree;

  private int mMenuId;
  private boolean isOldMenu;// 是否是之前的按钮.
  private String mSumBorrow;//已有借款合计
  private String mSumBorrowName;//需更新字段key
  private SystemConstant systemConstant;//系统变量,例如请假申请是否允许申请和补填
  private ArrayList<FormDetail> formDetails = new ArrayList<>();
  //    private RadioButton mRbFour;

  public static ToDoFormDetailFragment newInstance(Task mtaskContent) {
    Bundle args = new Bundle();

    args.putSerializable(EXTRA_TASK, mtaskContent);
    ToDoFormDetailFragment fragment = new ToDoFormDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    setHasOptionsMenu(true);
    mActivity = (BaseVolleyActivity) getActivity();
    mUser = CurrentUser.newInstance(getActivity());
    mTask = (Task) getArguments().getSerializable(EXTRA_TASK);
    if (mTask == null) return;
    mTaskId = mTask.getMyTaksId();
    mUserNodeType = mTask.getUserNodeType();
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_form_detail, container, false);
    setUpViews(v);

    volleyPostInit();
    return v;
  }

  @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mMenuId != 0) {
      inflater.inflate(mMenuId, menu);
    }
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    Intent i;
    // 待办
    switch (item.getItemId()) {
      case android.R.id.home:

        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }

        return true;
      case R.id.menu_item_confirm:
        LogUtil.i("ToDooperation=" + mOperation);
        if ((mTask.getProcessDefinitionId()).contains("SysErrorFeedback")) {
          ToastUtil.show(R.string.notSupportFlow);
        } else {
          volleyPostComplete(mOperation);
        }

        return true;
      // 转交办理菜单
      case R.id.menu_item_convert:
        i = new Intent(getActivity(), ChangeHandleActivity.class);
        i.putExtra(ChangeHandleFragment.EXTRA_TASK_ID, mTaskId);
        startActivityForResult(i, REQUEST_CONVERT);
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }

  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != Activity.RESULT_OK) {
      return;
    }
    switch (requestCode) {
      case REQUEST_CONVERT:
        getActivity().setResult(Activity.RESULT_OK);
        getActivity().finish();
        break;
      case REQUEST_FORMDETAIL:
        volleyPostInit();
        break;

      default:
        break;
    }
  }

  private void setUpViews(View v) {
    mListView = (ListView) v.findViewById(R.id.lv_container);

    mBtnChild = new Button(getActivity());
    mBtnChild.setText(R.string.checkDetail);
    mBtnChild.setTextColor(Color.WHITE);
    mBtnChild.setBackgroundResource(R.drawable.selector_buttonshape);

    mBtnChild.setOnClickListener(new OnClickListener() {

      @Override public void onClick(View v) {
        //表单信息跳转
        //加班单: 创建人为登录人可以编辑,跳转到加班子表列表界面
        if ((mTask.getProcessDefinitionId()).contains("rAttendOverTimeTotal")
            && mTask.getCreatorId().equalsIgnoreCase(mUser.getUserId())) {
          Intent intent = new Intent(getActivity(), CheckOverChildListActivity.class);
          intent.putExtra(CheckOverListFragment.EXTRA_PID, mTask.getBusinessKey());
          intent.putExtra(CheckOverListFragment.EXTRA_DATASTATUS, DataStatus.NEW);
          intent.putExtra(CheckOverListFragment.EXTRA_OVERTIMETYPE, "1");
          startActivityForResult(intent, REQUEST_FORMDETAIL);
        } else if ((mTask.getProcessDefinitionId()).contains("holiday")
            && mTask.getCreatorId()
            .equalsIgnoreCase(mUser.getUserId())
            && systemConstant.getIfAllowSupplement_holy() != null) {
          //请假
          startCheckDetail(CheckDetailFragment.VALUE_HOLY,
              systemConstant.getIfAllowSupplement_holy());
        } else if ((mTask.getProcessDefinitionId()).contains("RAttendBusinessTripApp")
            && mTask.getCreatorId().equalsIgnoreCase(mUser.getUserId())
            && systemConstant.getIfAllowSupplement_trip() != null) {
          //差旅
          startCheckDetail(CheckDetailFragment.VALUE_TRIP,
              systemConstant.getIfAllowSupplement_trip());
        } else if ((mTask.getProcessDefinitionId()).contains("rAttendOutWorkTotalFlow")
            && mTask.getCreatorId().equalsIgnoreCase(mUser.getUserId())) {
          //外出
          Intent intent = new Intent(getActivity(), CheckOutChildListActivity.class);
          intent.putExtra(CheckOutListFragment.EXTRA_PID, mTask.getBusinessKey());
          intent.putExtra(CheckOutListFragment.EXTRA_DATASTATUS, DataStatus.CHECK_PASS);
          intent.putExtra(CheckOutListFragment.EXTRA_IFLATERWRITE, "T");//流程中显示实际时间,按补填处理
          startActivityForResult(intent, REQUEST_FORMDETAIL);
          //证章申请填写实际归还时间
        } else if ((mTask.getProcessDefinitionId()).contains("SealsUse") && mTask.getCreatorId()
            .equalsIgnoreCase(mUser.getUserId())) {
          SealUseDetailParams params = new SealUseDetailParams();
          params.setType(BaseParams.TYPE_DETAIL);
          params.setTitle(MyStringUtil.connect(R.string.sealUse, R.string.detail1));
          params.setItem(new RSealsUseApp().setId(mTask.getBusinessKey()));
          params.setShowMenuConfirm(true);
          params.setEditBackTime(true);
          SealUseDetailActivity.newInstance(ToDoFormDetailFragment.this,
              SealUseDetailActivity.class, params, REQUEST_FORMDETAIL);
        } else {
          Intent intent = new Intent(getActivity(), FormChildLIstActivity.class);
          intent.putExtra(FormChildListFragment.EXTRA_CHILD_LIST,
              mFormDetailOriginal.getDetailList());
          startActivity(intent);
        }
      }
    });
    mListView.addFooterView(mBtnChild);

    View headerView = View.inflate(getActivity(), R.layout.view_header_form_detail, null);

    TextView mTvName = (TextView) headerView.findViewById(R.id.tv_hostName_formDetailFragment);
    mTvName.setText(SharedPreferencesUtil.getString(getActivity(), SharedPreferencesUtil.NAME, ""));
    mEtAdvise = (EditText) headerView.findViewById(R.id.et_examineAdvise);
    // 显示不同的界面效果
    RadioGroup mRg = (RadioGroup) headerView.findViewById(R.id.rg);
    RadioButton mRbOne = (RadioButton) headerView.findViewById(R.id.rb_one);
    mRbTwo = (RadioButton) headerView.findViewById(R.id.rb_two);
    mRbThree = (RadioButton) headerView.findViewById(R.id.rb_three);
    //        mRbFour = (RadioButton) headerView.findViewById(R.id.rb_four);

    String name1 = mTask.getRadio1Name();
    String name2 = mTask.getRadio2Name();
    String name3 = mTask.getRadio3Name();
    mRbOne.setText(name1);
    mRbTwo.setText(name2);
    mRbThree.setText(name3);

    if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.SIGN)) {
      // 会签环节:
      // 单选按钮显示: 显示同意,反对,弃权
      // 单选按钮操作.
      // 菜单项: 确定
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      mRbThree.setVisibility(View.VISIBLE);

      //			mRbOne.setText("同意");
      //			mRbTwo.setText("反对");
      //			mRbThree.setText("弃权");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_AGAINST);
      mRbThree.setTag(TYPE_ABORT);

      mMenuId = R.menu.menu_confirm;
    } else if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.AUTH)) {
      // 独裁环节:
      // 单选按钮: 同意,反对
      // 菜单项: 确定 ,转交办理.
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      //			mRbOne.setText("同意");
      //			mRbTwo.setText("反对");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_AGAINST);

      mMenuId = R.menu.menu_confirm_convert;
    } else if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.CONFIRM)) {
      // c)确认环节：：
      // 确认无误、
      // 异常退回(同意,反对)
      //转交办理
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      //			mRbOne.setText("确认无误");
      //			mRbTwo.setText("异常退出");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_AGAINST);

      mMenuId = R.menu.menu_confirm_convert;
    } else if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.DEAL)) {
      // 业务处理环节：（由于手机端流程处理暂时不支持编辑保存，建议该类型的环节不予手机端处理，即界面不显示任何按钮，
      // 提示请在网页端处理） 不显示按钮
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      //			mRbOne.setText("处理完成");
      //			mRbTwo.setText("未处理");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_AGAINST);

      mMenuId = R.menu.menu_confirm_convert;
    } else if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.APPLY)) {
      // f)申请填报(apply)
      //
      // 确认提交(同意的接口)
      mRbOne.setVisibility(View.VISIBLE);

      //			mRbOne.setText("确认提交");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setVisibility(View.VISIBLE);
      mRbTwo.setTag(TYPE_STOP);
      mRbTwo.setText(R.string.stopApply);
      mMenuId = R.menu.menu_confirm;
    } else if (MyStringUtil.equalsIgnoreCase(mUserNodeType, Task.DEFAULT)) {
      // e)默认审批环节模式(default)xfg
      //
      // 同意(原来相同)
      // 反对(参数是驳回上一环节参数)
      // 驳回发起人(不变)
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      mRbThree.setVisibility(View.VISIBLE);

      //			mRbOne.setText("同意");
      //			mRbTwo.setText("反对");
      //			mRbThree.setText("驳回发起人");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_REFUSE);
      mRbThree.setTag(TYPE_REFUSE_TO_ORGANIZER);

      mMenuId = R.menu.menu_confirm_convert;
    } else {
      // userNodeType为空时,兼容以前的按钮.
      isOldMenu = true;
      mRbOne.setVisibility(View.VISIBLE);
      mRbTwo.setVisibility(View.VISIBLE);
      mRbThree.setVisibility(View.VISIBLE);

      mRbOne.setText("同意");
      mRbTwo.setText("驳回");
      mRbThree.setText("驳回发起人");

      mRbOne.setTag(TYPE_AGREE);
      mRbTwo.setTag(TYPE_REFUSE);
      mRbThree.setTag(TYPE_REFUSE_TO_ORGANIZER);

      mMenuId = R.menu.menu_confirm_convert;
    }

    mRg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

      @Override public void onCheckedChanged(RadioGroup group, int checkedId) {
        RadioButton selectRb = (RadioButton) group.findViewById(checkedId);
        try {
          mOperation = (Integer) selectRb.getTag();
        } catch (Exception e) {
          // Auto-generated catch block
          e.printStackTrace();
        }
      }
    });
    mRbOne.setChecked(true);
    mListView.addHeaderView(headerView);
  }

  private void volleyPostInit() {

    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_FORM_INFO);
    HashMap<String, String> params = new HashMap<>();

    params.put("taskId", mTaskId);
    MyUtils.showDialogLoading(getActivity());
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        //LogUtil.i("待办事宜====" + arg0);

        mFormDetailOriginal = new Gson().fromJson(arg0, FormDetailOriginal.class);

        systemConstant = mFormDetailOriginal.getSystemConstant();
        formDetails = mFormDetailOriginal.getDataList();
        //如果是财务报销，重新获取已有借款合计，更新借款合计value值
        if (!TextUtils.isEmpty(mFormDetailOriginal.getServiceId()) && ("rExpenseInExpMain").equals(
            mFormDetailOriginal.getServiceId())) {
          if (!TextUtils.isEmpty(mFormDetailOriginal.getRecUserJobNo()) && !TextUtils.isEmpty(
              mFormDetailOriginal.getCustomAttrs())) {
            getSumBorrow();
          }
        }
        updateForm();//将isHiddend为true的字段隐藏掉
        getAdapter(formDetails);
        mAdapter.notifyDataSetChanged();

        if (mFormDetailOriginal.getDetailList() == null
            || mFormDetailOriginal.getDetailList().size() == 0) {

          //加班单,请假,差旅并且创建人为登录人时显示表单详情按钮并且跳转到可编辑的界面
          //if (!(mTask.getProcessDefinitionId()).contains("rAttendOverTimeTotal")
          //    || !mTask.getCreatorId()
          //    .equalsIgnoreCase(CurrentUser.newInstance(getActivity()).getUserId())) {
          //  mListView.removeFooterView(mBtnChild);
          //}

          if (!isVisibility()) {
            mListView.removeFooterView(mBtnChild);
          }
        }

        //特殊处理,isFirstNode时,显示终止流程,(因为第一环节代表自己发起的,可以终止)
        if (mFormDetailOriginal.getIsFirstNode()) {
          //                    mRbFour.setVisibility(View.VISIBLE);
          //                    mRbFour.setTag(TYPE_STOP);
          if (isOldMenu) {
            // 如果是第一个节点,兼容老版本,禁用驳回和驳回发起人.
            mRbTwo.setVisibility(View.GONE);
            mRbThree.setVisibility(View.GONE);
          }
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {

      }
    });
  }

  private boolean isVisibility() {
    //加班单,请假,差旅并且创建人为登录人时显示表单详情按钮,其他流程隐藏,并且跳转到可编辑的界面
    return ((mTask.getProcessDefinitionId()).contains("rAttendOverTimeTotal")
        || (mTask.getProcessDefinitionId()).contains("holiday")
        || (mTask.getProcessDefinitionId()).contains("SealsUse")
        || (mTask.getProcessDefinitionId()).contains("RAttendBusinessTripApp")
        || (mTask.getProcessDefinitionId()).contains("rAttendOutWorkTotalFlow"))
        && mTask.getCreatorId()
        .equalsIgnoreCase(CurrentUser.newInstance(getActivity()).getUserId());
  }

  public void getSumBorrow() {
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_ADD_EMPLOYEE_LOAN_DETAIL);
    HashMap<String, String> params = new HashMap<>();
    // "customAttrs": "100014-DJLB-CWZC-YGJKZC,借款合计",
    String[] customAttrs = (mFormDetailOriginal.getCustomAttrs()).split(",");
    String mCertificateCode = customAttrs[0];
    mSumBorrowName = customAttrs[1];
    params.put("certificateCode", mCertificateCode);
    params.put("userJobNo", mFormDetailOriginal.getRecUserJobNo());
    MyUtils.showDialogLoading(getActivity());
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        MyUtils.dismissDialog();
        CertificateNoContent[] array = new Gson().fromJson(arg0, CertificateNoContent[].class);
        CertificateNoContent mNoContent = array[0];
        mSumBorrow = mNoContent.getSumBorrow();//已有借款合计
        //循环遍历，已有借款合计name中包含mSumBorrowName，就更新对应value值
        for (int i = 0; i < formDetails.size(); i++) {
          String name = formDetails.get(i).getName();
          String isHidden = formDetails.get(i).getIsHidden();//false：字段显示在界面上，true:隐藏
          if (name.contains(mSumBorrowName)) {
            formDetails.get(i).setValue(mSumBorrow);
          }
          if ("true".equalsIgnoreCase(isHidden)) {
            formDetails.remove(i);
            i--;
          }
        }
        //                //适配数据
        //                getAdapter(formDetails);
        //                mAdapter.notifyDataSetChanged();
      }

      @Override public void onVolleyError(VolleyError arg0) {
        //updateForm();
      }
    });
  }

  private void updateForm() {
    //没有获取到借款合计，将isHiddend为true的字段隐藏掉
    for (int i = 0; i < formDetails.size(); i++) {
      String isHidden = formDetails.get(i).getIsHidden();//false：字段显示在界面上，true:隐藏
      if ("true".equalsIgnoreCase(isHidden)) {
        formDetails.remove(i);
        i--;
      }
    }
    //        //适配数据
    //        getAdapter(mformDetails);
    //        mAdapter.notifyDataSetChanged();
  }

  private void getAdapter(ArrayList<FormDetail> formDetails) {
    if (mAdapter == null) {
      mAdapter = new FormDetailAdapter(getActivity(), formDetails);
      mListView.setAdapter(mAdapter);
    } else {
      mAdapter.notifyDataSetChanged();
    }
  }

  private void volleyPostComplete(int type) {
    String voteAgree = "";
    String back = "";
    switch (type) {
      case TYPE_AGREE:

        voteAgree = "1";
        back = "0";
        if (mAdapter != null && mAdapter.isNeccessaryExist) {

          DialogUtil.showMessage(this, R.string.turn_to_web);
          //                    ToastUtil.show(R.string.turn_to_web);
          return;
        }
        break;
      //特殊处理终止流程.
      case TYPE_STOP:
        volleyPostStop();
        //ToastUtil.show("终止流程,不结束页面,证明return结束当前方法");
        return;
      case TYPE_REFUSE:

        voteAgree = "3";
        back = "1";
        break;
      case TYPE_REFUSE_TO_ORGANIZER:

        voteAgree = "3";
        back = "2";
        break;
      case TYPE_AGAINST:

        voteAgree = "2";
        back = "0";
        break;
      case TYPE_ABORT:

        voteAgree = "0";
        back = "";
        break;

      default:
        break;
    }
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_COMPLETE);
    HashMap<String, String> params = new HashMap<>();
    params.put("taskId", mTaskId);
    params.put("voteContent", mEtAdvise.getText().toString().trim());

    params.put("voteAgree", voteAgree);
    params.put("back", back);
    params.put("businessKey", mTask.getBusinessKey());
    MyUtils.showDialogLoading(getActivity(), getString(R.string.dataProcessLoading));
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {

        CompleteMessage completeMessage = new Gson().fromJson(arg0, CompleteMessage.class);
        if (completeMessage == null) {
          ToastUtil.show(R.string.wrong_data);
          return;
        }
        if (completeMessage.getResult() == 1) {
          ToastUtil.show(R.string.processTaskSuccess);
          HintNumber.newInstance(mActivity).reduce(HintNumber.TASK);

          getActivity().setResult(Activity.RESULT_OK);
          getActivity().finish();
        } else {
          //ToastUtil.show(R.string.failure_operation);
          showDialog(BaseConfirmDialogFragment.newInstance(completeMessage.getMessage(),
              R.string.processTaskFail), 0);
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {

      }
    });
  }

  // 终止流程
  private void volleyPostStop() {
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_TASK_STOP);
    HashMap<String, String> params = new HashMap<>();
    params.put("runId", mTask.getRunId());
    LogUtil.i("终止流程params====" + params.toString());
    MyUtils.showDialogLoading(getActivity());
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        LogUtil.i("终止流程====" + arg0);
        try {
          MyUtils.dismissDialog();
          // 解析
          SuccessMessage result = new Gson().fromJson(arg0, SuccessMessage.class);
          if (null == result || null == result.getResult()) {
            ToastUtil.show(R.string.failure_operation);
            return;
          }
          String successType = result.getResult();
          if (successType.equals(SuccessMessage.FAILURE)) {
            ToastUtil.show(result.getMessage());
            return;
          }
          if (successType.equals(SuccessMessage.SUCCESS)) {
            ToastUtil.show(R.string.success_operation);

            getActivity().setResult(Activity.RESULT_OK);
            getActivity().finish();
          }
        } catch (JsonSyntaxException e) {
          ToastUtil.show(R.string.wrong_data);
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        ToastUtil.show(R.string.failure_operation);
      }
    });
  }

  /**
   * @param type 类型
   * @param ifAllowSupplement 是否允许申请和补填
   */
  private void startCheckDetail(String type, String ifAllowSupplement) {
    Intent i = new Intent(getActivity(), CheckDetailActivity.class);
    i.putExtra(CheckDetailFragment.EXTRA_REQUISITION_ID, mTask.getBusinessKey());
    i.putExtra(CheckDetailFragment.EXTRA_TYPE, type);
    i.putExtra(CheckDetailFragment.EXTRA_INTERRUPT, "");
    i.putExtra(CheckDetailFragment.EXTRA_FILE, "");
    i.putExtra(CheckDetailFragment.EXTRA_DATASTATUS, "todo");
    i.putExtra(CheckDetailFragment.EXTRA_IFALLOW, ifAllowSupplement);
    startActivityForResult(i, REQUEST_FORMDETAIL);
  }
}
